// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ARRAY2D_H_
#define ARRAY2D_H_

#include <memory>

template <typename T>
class Array2D {
 public:
  Array2D() : width_(0), height_(0) {}
  ~Array2D() {}

  void Realloc(int width, int height) {
    width_ = width;
    height_ = height;
    data_.reset(new T[width_ * height_]);
  }

  T& operator()(int i, int j) {
    return data_[j * width_ + i];
  }

  const T& operator()(int i, int j) const {
    return data_[j * width_ + i];
  }

  int width() const { return width_; }
  int height() const { return height_; }

 private:
  int width_;
  int height_;
  std::unique_ptr<T[]> data_;
};

#endif  // ARRAY2D_H_
